package designpattern.compoundPattern;

import java.util.ArrayList;
import java.util.List;

/**组合模式
 * 注：flock即一群的意思
 */
public class Flock implements Quackable{
    List<Quackable> quackers=new ArrayList<>();

    public void add(Quackable quacker){
        quackers.add(quacker);
    }
    @Override
    public void quack() {
        for(Quackable q:quackers){
            q.quack();
        }
    }

    @Override
    public void registerObserver(Observer observer) {
        for(Quackable q:quackers){
            q.registerObserver(observer);
        }
    }

    @Override
    public void notifyObservers() {
        throw new RuntimeException("no such method");
    }
}
